package prueba.principal.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class UsersReader {
	
	private static final String FILE="/nombres.txt";
	private static ArrayList<String> listado=null;
	
	private static UsersReader INSTANCE = null;
	
	static {
		INSTANCE=new UsersReader();
	}
	
	public static ArrayList<String> read(){
		
		ArrayList<String> lista = new ArrayList<String>();
		
		try{
			
			//Creamos un buffered reader para poder leer el fichero linea a linea
			InputStream is = INSTANCE.getClass().getResourceAsStream(FILE);
			BufferedReader bufRead = new BufferedReader(new InputStreamReader(is));

			String linea=bufRead.readLine();
						
			while(linea!=null){
				
				lista.add(linea);
				linea=bufRead.readLine();
				
			}		

		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		return lista;
	}
	
	public static ArrayList<String> getUsers(){
		
		if(listado!=null)
			return listado;
		
		listado=read();
		
		return listado;
	}

}
